#include <bolt.h>
#include "netnode.h"

void nn_params_init(struct nn_params *params, int nn_type)
{
  memset(params, 0, sizeof(struct nn_params));
  params->snack = 1;
  params->ack_behave = -1;
  params->encrypt_pre_overhead = DEFAULT_ENCRYPT_PRE_OVERHEAD;
  params->encrypt_block_size = DEFAULT_ENCRYPT_BLOCK_SIZE;
  params->encrypt_post_overhead = DEFAULT_ENCRYPT_POST_OVERHEAD;
  params->mss_ff = -1;
  params->embargo_fast_rxmit_ctr = 4;
  params->nl = NL_DEFAULT;
  params->minrto = TP_RTOMIN;
  params->maxrto = TP_RTOMAX;
  params->maxrto_ctr = TP_TIMEOUT;
  params->maxpersist_ctr = TP_MAXPERSIST_CTR;
  params->rtopersist_max = TP_RTOPERSIST_MAX;
  if (nn_type == NN_TYPE_WAN)
    params->divport = DEF_B_PORT;
  else
    params->divport = DEF_A_PORT;

}

void nn_params_show(struct nn_params *params)
{
  printf (" buf %d\n", params->buf);
  printf (" rbuf %d\n", params->rbuf);
  printf (" rate %d\n", params->rate);
  printf (" min_rate %d\n", params->min_rate);
  printf (" cc %d\n", params->cc);
  printf (" divport %d\n", params->divport);
  printf (" ts %d\n", params->ts);
  printf (" snack %d\n", params->snack);
  printf (" nodelay %d\n", params->nodelay);
  printf (" snack_delay %d\n", params->snack_delay);
  printf (" ack_behave %d\n", params->ack_behave);
  printf (" ack_delay %d\n", params->ack_delay);
  printf (" tcponly %d\n", params->tcponly);
  printf (" next_hop %d\n", params->next_hop);
  printf (" irto %d\n", params->irto);
  printf (" vegas_alpha %d\n", params->vegas_alpha);
  printf (" vegas_beta %d\n", params->vegas_beta);
  printf (" vegas_gamma %d\n", params->vegas_gamma);
  printf (" vegas_ss %d\n", params->vegas_ss);
  printf (" flow_control_cap %d\n", params->flow_control_cap);
  printf (" tap_no_phy %d\n", params->tap_no_phy);
  printf (" scps_security %d\n", params->scps_security);
  printf (" layering %d\n", params->layering);
  printf (" overhead %d\n", params->overhead);
  printf (" mss_ff %d\n", params->mss_ff);
  printf (" nl %d\n", params->nl);
  printf (" minrto %u\n", params->minrto);
  printf (" maxrto %u\n", params->maxrto);
  printf (" maxrto_ctr %u\n", params->maxrto_ctr);
  printf (" maxpersist_ctr %u\n", params->maxpersist_ctr);
  printf (" rtopersist_max %u\n", params->rtopersist_max);
  printf (" rto_to_persist_ctr %u\n", params->rto_to_persist_ctr);
  printf (" embargo_fast_rxmit_ctr %u\n", params->embargo_fast_rxmit_ctr);
  printf (" msltimeout %d\n", params->msltimeout);
  printf (" tp_compress %d\n", params->tp_compress);
  printf (" div_addr %d\n", params->div_addr);
  printf (" div_port %d\n", params->div_port);

  int i;
  printf(" encrypt_ipsec_downstream %d\n", params->encrypt_ipsec_downstream);
  printf(" encrypt_pre_overhead %u\n", params->encrypt_pre_overhead);
  printf(" encrypt_block_size %u\n", params->encrypt_block_size);
  printf(" encrypt_post_overhead %u\n", params->encrypt_post_overhead);
  printf(" ecbs1 id %u len %u value %s\n", 
      params->ecbs1, params->ecbs1_len, params->ecbs1_value);
  printf(" ecbs2 id %u len %u value %s\n", 
      params->ecbs2, params->ecbs2_len, params->ecbs2_value);
  char addrstr[INET_ADDRSTRLEN + 1],maskstr[INET_ADDRSTRLEN + 1];
  for (i = 0; i < params->addr_cnt; i++) {
    printf (" >address %s/%s\n", 
      ip2str(params->addr[i], addrstr),
      ip2str(params->mask[i], maskstr));
  }
}

struct nn_params * get_nn_params(int id)
{
  struct netnode * nn = netnode_get(id);
  if (nn) 
    return &nn->params;
  else
    return NULL;
}

BOLT(nn_buf, "netnode <id> buf <size>")
{
  uint32_t buf;
  const char *argz = pop_argz();
  if (!str2u32(argz, &buf)) {
    printf("invalid buf\n");
    return;
  }
  uint32_t id;
  argz = pop_argz();
  if (!str2u32(argz, &id)) {
    printf("invalid id\n");
    return;
  }
  struct nn_params *params = get_nn_params(id);
  if (params != NULL) {
    params->buf = buf;
    printf("success\n");
  } else
    printf("failure\n");
}

BOLT(nn_rbuf, "netnode <id> rbuf <size>")
{
  uint32_t rbuf;
  const char *argz = pop_argz();
  if (!str2u32(argz, &rbuf)) {
    printf("invalid rbuf\n");
    return;
  }
  uint32_t id;
  argz = pop_argz();
  if (!str2u32(argz, &id)) {
    printf("invalid id\n");
    return;
  }
  struct nn_params *params = get_nn_params(id);
  if (params == NULL) {
    printf ("netnode not use\n");
  } else
    params->rbuf = rbuf;
}

BOLT(nn_rate, "netnode <id> rate <rate>")
{
  uint32_t rate;
  const char *argz = pop_argz();
  if (!str2u32(argz, &rate)) {
    printf("invalid rate\n");
    return;
  }
  uint32_t id;
  argz = pop_argz();
  if (!str2u32(argz, &id) || id >= NETNODE_MAX) {
    printf("invalid id\n");
    return;
  }
  struct nn_params *nn = get_nn_params(id);
  if (nn == NULL) {
    printf ("netnode not use\n");
  } else {
    nn->rate = rate;
    if (nn->min_rate == 0)
      nn->min_rate = rate;
  }
}

BOLT(nn_min_rate, "netnode <id> min-rate <rate>")
{
  uint32_t min_rate;
  const char *argz = pop_argz();
  if (!str2u32(argz, &min_rate)) {
    printf("invalid min rate\n");
    return;
  }
  uint32_t id;
  argz = pop_argz();
  if (!str2u32(argz, &id)) {
    printf("invalid id\n");
    return;
  }
  struct nn_params *nn = get_nn_params(id);
  if (nn == NULL) {
    printf ("netnode not use\n");
    return;
  } 
  if (min_rate == 0)
    nn->min_rate = nn->rate;
  else
    nn->min_rate = min_rate;
}

BOLT(nn_cc, "netnode <id> cc <cc>")
{
  uint32_t cc;
  const char *argz = pop_argz();
  if (!str2u32(argz, &cc)) {
    printf("invalid cc\n");
    return;
  }
  uint32_t id;
  argz = pop_argz();
  if (!str2u32(argz, &id)) {
    printf("invalid id\n");
    return;
  }
  struct nn_params *nn = get_nn_params(id);
  if (nn == NULL) {
    printf ("netnode not use\n");
    return;
  } 
  nn->cc = cc;
}

BOLT(nn_tap_no_phy, "netnode <id> tap-no-phy <no-phy>")
{
  uint32_t tap_no_phy;
  const char *argz = pop_argz();
  if (!str2u32(argz, &tap_no_phy)) {
    printf("invalid tap_no_phy\n");
    return;
  }
  uint32_t id;
  argz = pop_argz();
  if (!str2u32(argz, &id)) {
    printf("invalid id\n");
    return;
  }
  struct nn_params *nn = get_nn_params(id);
  if (nn == NULL) {
    printf ("netnode not use\n");
    return;
  } 
  nn->tap_no_phy = tap_no_phy;
}

BOLT(nn_divport, "netnode <id> divport <port>")
{
  uint16_t divport;
  const char *argz = pop_argz();
  if (!str2u16(argz, &divport)) {
    printf("invalid divport\n");
    return;
  }
  uint32_t id;
  argz = pop_argz();
  if (!str2u32(argz, &id)) {
    printf("invalid id\n");
    return;
  }
  struct nn_params *nn = get_nn_params(id);
  if (nn == NULL) {
    printf ("netnode not use\n");
    return;
  } 
  nn->divport = divport;
}
       
BOLT(nn_layering, "netnode <id> layering <layering>")
{
  uint32_t layering;
  const char *argz = pop_argz();
  if (!str2u32(argz, &layering)) {
    printf("invalid layering\n");
    return;
  }
  uint32_t id;
  argz = pop_argz();
  if (!str2u32(argz, &id)) {
    printf("invalid id\n");
    return;
  }
  struct nn_params *nn = get_nn_params(id);
  if (nn == NULL) {
    printf ("netnode not use\n");
    return;
  } 
  nn->layering = layering;
}

BOLT(nn_overhead, "netnode <id> overhead <overhead>")
{
  uint32_t overhead;
  const char *argz = pop_argz();
  if (!str2u32(argz, &overhead)) {
    printf("invalid overhead\n");
    return;
  }
  uint32_t id;
  argz = pop_argz();
  if (!str2u32(argz, &id)) {
    printf("invalid id\n");
    return;
  }
  struct nn_params *nn = get_nn_params(id);
  if (nn == NULL) {
    printf ("netnode not use\n");
    return;
  } 
  nn->overhead = overhead;
}

BOLT(nn_mss_ff, "netnode <id> mss-ff <mss-ff>")
{
  uint32_t mss_ff;
  const char *argz = pop_argz();
  if (!str2u32(argz, &mss_ff)) {
    printf("invalid mss_ff\n");
    return;
  }
  uint32_t id;
  argz = pop_argz();
  if (!str2u32(argz, &id)) {
    printf("invalid id\n");
    return;
  }
  struct nn_params *nn = get_nn_params(id);
  if (nn == NULL) {
    printf ("netnode not use\n");
    return;
  } 
  nn->mss_ff = mss_ff;
}

BOLT(nn_ts, "netnode <id> ts <ts>")
{
  uint32_t ts;
  const char *argz = pop_argz();
  if (!str2u32(argz, &ts)) {
    printf("invalid ts\n");
    return;
  }
  uint32_t id;
  argz = pop_argz();
  if (!str2u32(argz, &id)) {
    printf("invalid id\n");
    return;
  }
  struct nn_params *nn = get_nn_params(id);
  if (nn == NULL) {
    printf ("netnode not use\n");
    return;
  } 
  nn->ts = ts;
}

BOLT(nn_snack_delay, "netnode <id> delay <delay>")
{
  uint32_t snack_delay;
  const char *argz = pop_argz();
  if (!str2u32(argz, &snack_delay)) {
    printf("invalid snack_delay\n");
    return;
  }
  uint32_t id;
  argz = pop_argz();
  if (!str2u32(argz, &id)) {
    printf("invalid id\n");
    return;
  }
  struct nn_params *nn = get_nn_params(id);
  if (nn == NULL) {
    printf ("netnode not use\n");
    return;
  } 
  nn->snack_delay = snack_delay;
}

BOLT(nn_snack_state, "netnode <id> snack <state>")
{
  uint32_t snack;
  const char *argz = pop_argz();
  if (!str2u32(argz, &snack)) {
    printf("invalid snack\n");
    return;
  }
  uint32_t id;
  argz = pop_argz();
  if (!str2u32(argz, &id)) {
    printf("invalid id\n");
    return;
  }
  struct nn_params *nn = get_nn_params(id);
  if (nn == NULL) {
    printf ("netnode not use\n");
    return;
  } 
  nn->snack = snack;
}

BOLT(nn_nodelay, "netnode <id> nodelay <nodelay>")
{
  uint32_t nodelay;
  const char *argz = pop_argz();
  if (!str2u32(argz, &nodelay)) {
    printf("invalid nodelay\n");
    return;
  }
  uint32_t id;
  argz = pop_argz();
  if (!str2u32(argz, &id)) {
    printf("invalid id\n");
    return;
  }
  struct nn_params *nn = get_nn_params(id);
  if (nn == NULL) {
    printf ("netnode not use\n");
    return;
  } 
  nn->nodelay = nodelay;
}

BOLT(nn_ack_delay, "netnode <id> ack-delay <delay>")
{
  uint32_t ack_delay;
  const char *argz = pop_argz();
  if (!str2u32(argz, &ack_delay)) {
    printf("invalid ack_delay\n");
    return;
  }
  uint32_t id;
  argz = pop_argz();
  if (!str2u32(argz, &id)) {
    printf("invalid id\n");
    return;
  }
  struct nn_params *nn = get_nn_params(id);
  if (nn == NULL) {
    printf ("netnode not use\n");
    return;
  } 
  nn->ack_delay = ack_delay;
}

BOLT(nn_ack_behave, "netnode <id> ack-behave <ack-behave>")
{
  uint32_t ack_behave;
  const char *argz = pop_argz();
  if (!str2u32(argz, &ack_behave)) {
    printf("invalid ack_behave\n");
    return;
  }
  uint32_t id;
  argz = pop_argz();
  if (!str2u32(argz, &id)) {
    printf("invalid id\n");
    return;
  }
  struct nn_params *nn = get_nn_params(id);
  if (nn == NULL) {
    printf ("netnode not use\n");
    return;
  } 
  nn->ack_behave = ack_behave;
}

BOLT(nn_tcponly, "netnode <id> tcponly <tcponly>")
{
  uint32_t tcponly;
  const char *argz = pop_argz();
  if (!str2u32(argz, &tcponly)) {
    printf("invalid tcponly\n");
    return;
  }
  uint32_t id;
  argz = pop_argz();
  if (!str2u32(argz, &id)) {
    printf("invalid id\n");
    return;
  }
  struct nn_params *nn = get_nn_params(id);
  if (nn == NULL) {
    printf ("netnode not use\n");
    return;
  } 
  nn->tcponly = tcponly;
}

BOLT(nn_next_hop, "netnode <id> next-hop <next-hop>")
{
  uint32_t next_hop;
  const char *argz = pop_argz();
  if (!ip2u32(argz, &next_hop)) {
    printf("invalid next hop\n");
    return;
  }
  uint32_t id;
  argz = pop_argz();
  if (!str2u32(argz, &id) || id >= NETNODE_MAX) {
    printf("invalid id\n");
    return;
  }
  struct nn_params *nn = get_nn_params(id);
  if (nn == NULL) {
    printf ("netnode not use\n");
    return;
  } 
  nn->next_hop = next_hop;
}

BOLT(nn_nl, "netnode <id> nl <nl>")
{
  uint32_t nl;
  const char *argz = pop_argz();
  if (!str2u32(argz, &nl)) {
    printf("invalid nl\n");
    return;
  }
  uint32_t id;
  argz = pop_argz();
  if (!str2u32(argz, &id) || id >= NETNODE_MAX) {
    printf("invalid id\n");
    return;
  }
  struct nn_params *nn = get_nn_params(id);
  if (nn == NULL) {
    printf ("netnode not use\n");
    return;
  } 
  nn->nl = nl;
}

BOLT(nn_en_post_overhead, "netnode <id> encrypto post-overhead <overhead>")
{
  uint32_t encrypt_post_overhead;
  const char *argz = pop_argz();
  if (!str2u32(argz, &encrypt_post_overhead)) {
    printf("invalid encrypt_post_overhead\n");
    return;
  }
  uint32_t id;
  argz = pop_argz();
  if (!str2u32(argz, &id) || id >= NETNODE_MAX) {
    printf("invalid id\n");
    return;
  }
  struct nn_params *nn = get_nn_params(id);
  if (nn == NULL) {
    printf ("netnode not use\n");
    return;
  } 
  nn->encrypt_post_overhead = encrypt_post_overhead;
}

BOLT(nn_en_block_size, "netnode <id> encrypt block-size <size>")
{
  uint32_t encrypt_block_size;
  const char *argz = pop_argz();
  if (!str2u32(argz, &encrypt_block_size)) {
    printf("invalid encrypt_block_size\n");
    return;
  }
  uint32_t id;
  argz = pop_argz();
  if (!str2u32(argz, &id) || id >= NETNODE_MAX) {
    printf("invalid id\n");
    return;
  }
  struct nn_params *nn = get_nn_params(id);
  if (nn == NULL) {
    printf ("netnode not use\n");
    return;
  } 
  nn->encrypt_block_size = encrypt_block_size;
}

BOLT(nn_en_pre_overhead, "netnode <id> encrypt pre-overhead <overhead>")
{
  uint32_t encrypt_pre_overhead;
  const char *argz = pop_argz();
  if (!str2u32(argz, &encrypt_pre_overhead)) {
    printf("invalid encrypt_pre_overhead\n");
    return;
  }
  uint32_t id;
  argz = pop_argz();
  if (!str2u32(argz, &id) || id >= NETNODE_MAX) {
    printf("invalid id\n");
    return;
  }
  struct nn_params *nn = get_nn_params(id);
  if (nn == NULL) {
    printf ("netnode not use\n");
    return;
  } 
  nn->encrypt_pre_overhead = encrypt_pre_overhead;
}

BOLT(nn_en_ipsec_downstream, "netnode <id> encrypt ipsec <downstream>")
{
  uint32_t encrypt_ipsec_downstream;
  const char *argz = pop_argz();
  if (!str2u32(argz, &encrypt_ipsec_downstream)) {
    printf("invalid encrypt_ipsec_downstream\n");
    return;
  }
  uint32_t id;
  argz = pop_argz();
  if (!str2u32(argz, &id) || id >= NETNODE_MAX) {
    printf("invalid id\n");
    return;
  }
  struct nn_params *nn = get_nn_params(id);
  if (nn == NULL) {
    printf ("netnode not use\n");
    return;
  } 
  nn->encrypt_ipsec_downstream = encrypt_ipsec_downstream;
}

BOLT(nn_tp_compress, "netnode <id> tp-compress <compress>")
{
  uint32_t tp_compress;
  const char *argz = pop_argz();
  if (!str2u32(argz, &tp_compress)) {
    printf("invalid tp compress\n");
    return;
  }
uint32_t id;
  argz = pop_argz();
  if (!str2u32(argz, &id) || id >= NETNODE_MAX) {
    printf("invalid id\n");
    return;
  }
  struct nn_params *nn = get_nn_params(id);
  if (nn == NULL) {
    printf ("netnode not use\n");
    return;
  } 
  nn->tp_compress = tp_compress;
}

BOLT(nn_div, "netnode <id> divert address <ip> <port>")
{
  uint32_t ip = 0;
  uint16_t port = 0;
 
  const char *argz = pop_argz();
  if (!str2u16(argz, &port)) {
    printf("invalid port\n");
    return;
  }
  argz = pop_argz();
  if (ip2u32(argz, &ip)) {
    printf("invalid ip\n");
    return;
  }
  uint32_t id;
  argz = pop_argz();
  if (!str2u32(argz, &id)) {
    printf("invalid id\n");
    return;
  }
  struct nn_params *nn = get_nn_params(id);
  if (nn == NULL) {
    printf ("netnode not use\n");
    return;
  } 
  nn->div_addr = ip;
  nn->div_port = port;
}

BOLT(nn_ecbs2, "netnode <id> ecbs2 <id> <value> <len>")
{
  uint32_t ecbs2,len;
  const char *value;
  
  const char *argz = pop_argz();
  if (!str2u32(argz, &len)) {
    printf("invalid len\n");
    return;
  }
  value = pop_argz();
  if (value == NULL || value[0] == 0 || strlen(value) >= MAX_ECBS_VALUE) {
    printf("invalid value\n");
    return;
  }
  if (!str2u32(argz, &ecbs2)) {
    printf("invalid ecbs2\n");
    return;
  }
  uint32_t id;
  argz = pop_argz();
  if (!str2u32(argz, &id)) {
    printf("invalid id\n");
    return;
  }
  struct nn_params *nn = get_nn_params(id);
  if (nn == NULL) {
    printf ("netnode not use\n");
    return;
  } 
  nn->ecbs2 = ecbs2;
  int offset = snprintf(nn->ecbs2_value, MAX_ECBS_VALUE - 1, "%s", value);
  nn->ecbs2_value[offset] = 0;
  nn->ecbs2_len = len;
}

BOLT(nn_ecbs1, "netnode <id> ecbs1 <esbs> <value> <len>")
{
  uint32_t ecbs1,len;
  const char *value;
  
  const char *argz = pop_argz();
  if (!str2u32(argz, &len)) {
    printf("invalid len\n");
    return;
  }
  value = pop_argz();
  if (value == NULL || value[0] == 0 || strlen(value) >= MAX_ECBS_VALUE) {
    printf("invalid value\n");
    return;
  }
  if (!str2u32(argz, &ecbs1)) {
    printf("invalid ecbs1\n");
    return;
  }
  uint32_t id;
  argz = pop_argz();
  if (!str2u32(argz, &id) || id >= NETNODE_MAX) {
    printf("invalid id\n");
    return;
  }
  struct nn_params *nn = get_nn_params(id);
  if (nn == NULL) {
    printf ("netnode not use\n");
    return;
  } 
  nn->ecbs1 = ecbs1;
  int offset = snprintf(nn->ecbs1_value, MAX_ECBS_VALUE - 1, "%s", value);
  nn->ecbs1_value[offset] = 0;
  nn->ecbs1_len = len;
}

BOLT(nn_maxrto_ctr, "netnode <id> maxrto-ctr <maxrto-ctr>")
{
  uint32_t v;  
  const char *argz = pop_argz();
  if (!str2u32(argz, &v)) {
    printf("invalid maxrto ctr\n");
    return;
  }
  uint32_t id;
  argz = pop_argz();
  if (!str2u32(argz, &id)) {
    printf("invalid id\n");
    return;
  }
  struct nn_params *nn = get_nn_params(id);
  if (nn == NULL) {
    printf ("netnode not use\n");
    return;
  } 
  nn->maxrto_ctr = v;
}

BOLT(nn_maxpersist_ctr, "netnode <id> maxpersist-ctr <maxpersist-ctr>")
{
  uint32_t v;  
  const char *argz = pop_argz();
  if (!str2u32(argz, &v)) {
    printf("invalid maxpersist ctr\n");
    return;
  }
  uint32_t id;
  argz = pop_argz();
  if (!str2u32(argz, &id)) {
    printf("invalid id\n");
    return;
  }
  struct nn_params *nn = get_nn_params(id);
  if (nn == NULL) {
    printf ("netnode not use\n");
    return;
  } 
  nn->maxpersist_ctr = v;
}

BOLT(nn_rtopersist_max, "netnode <id> rtopersist-max <rtopersist-max>")
{
  uint32_t v;  
  const char *argz = pop_argz();
  if (!str2u32(argz, &v)) {
    printf("invalid rtopersist max\n");
    return;
  }
  uint32_t id;
  argz = pop_argz();
  if (!str2u32(argz, &id) || id >= NETNODE_MAX) {
    printf("invalid id\n");
    return;
  }
  struct nn_params *nn = get_nn_params(id);
  if (nn == NULL) {   
    printf ("netnode not use\n");
    return;
  } 
  nn->rtopersist_max = v;
}

BOLT(nn_rto_to_persist_ctr, "netnode <id> rto-to-persist-ctr <rto-to-persist-ctr>")
{
  uint32_t v;  
  const char *argz = pop_argz();
  if (!str2u32(argz, &v)) {
    printf("invalid rto to persist ctr\n");
    return;
  }
  uint32_t id;
  argz = pop_argz();
  if (!str2u32(argz, &id)) {
    printf("invalid id\n");
    return;
  }
  struct nn_params *params = get_nn_params(id);
  if (params == NULL) {
    printf ("netnode not use\n");
    return;
  } 
  params->rto_to_persist_ctr = v;
}

BOLT(gw_nn_rxmit_ctr, "netnode <id> fast-rxmit-ctr <fast-rxmit-ctr>")
{
  uint16_t v;  
  const char *argz = pop_argz();
  if (!str2u16(argz, &v)) {
    printf("invalid rto to persist ctr\n");
    return;
  }
  uint32_t id;
  argz = pop_argz();
  if (!str2u32(argz, &id)) {
    printf("invalid id\n");
    return;
  }
  struct nn_params *params = get_nn_params(id);
  if (params == NULL) {
    printf ("netnode not use\n");
    return;
  } 
  params->embargo_fast_rxmit_ctr = (int)v;
}
    
BOLT(nn_2msltimeout, "netnode <id> 2msltimeout <2msltimeout>")
{
  uint16_t v;  
  const char *argz = pop_argz();
  if (!str2u16(argz, &v)) {
    printf("invalid 2msl timeout\n");
    return;
  }
  uint32_t id;
  argz = pop_argz();
  if (!str2u32(argz, &id)) {
    printf("invalid id\n");
    return;
  }
  struct nn_params *params = get_nn_params(id);
  if (params == NULL) {
    printf ("netnode not use\n");
    return;
  } 
  params->msltimeout = (int)v;
}

BOLT(nn_max_rto, "netnode <id> max-rto <max>")
{
  uint32_t rto;  
  const char *argz = pop_argz();
  if (!str2u32(argz, &rto)) {
    printf("invalid rto\n");
    return;
  }
  uint32_t id;
  argz = pop_argz();
  if (!str2u32(argz, &id)) {
    printf("invalid id\n");
    return;
  }
  struct nn_params *params = get_nn_params(id);
  if (params == NULL) {
    printf ("netnode not use\n");
    return;
  } 
  params->maxrto = rto;
}

BOLT(nn_min_rto, "netnode <id> min-rto <min>")
{
  uint32_t rto;  
  const char *argz = pop_argz();
  if (!str2u32(argz, &rto)) {
    printf("invalid rto\n");
    return;
  }
  uint32_t id;
  argz = pop_argz();
  if (!str2u32(argz, &id) || id >= NETNODE_MAX) {
    printf("invalid id\n");
    return;
  }
  struct nn_params *nn = get_nn_params(id);
  if (nn == NULL) {
    printf ("netnode not use\n");
    return;
  } 
  nn->minrto = rto;
}

BOLT(nn_rto_initial, "netnode <id> init-rto <initial>")
{
  uint32_t rto;  
  const char *argz = pop_argz();
  if (!str2u32(argz, &rto)) {
    printf("invalid rto\n");
    return;
  }
  uint32_t id;
  argz = pop_argz();
  if (!str2u32(argz, &id)) {
    printf("invalid id\n");
    return;
  }
  struct nn_params *params = get_nn_params(id);
  if (params == NULL) {
    printf ("netnode not use\n");
    return;
  } 
  params->irto = rto;
}

BOLT(nn_vegas, "netnode <id> vegas <alpha> <beta> <gamma> <ss>")
{
  uint16_t alpha,beta,gamma,ss;  
  const char *argz = pop_argz();
  if (!str2u16(argz, &ss)) {
    printf("invalid vegas ss\n");
    return;
  }
  argz = pop_argz();
  if (!str2u16(argz, &gamma)) {
    printf("invalid vegas gamma\n");
    return;
  }
  
  argz = pop_argz();
  if (!str2u16(argz, &beta)) {
    printf("invalid vegas beta\n");
    return;
  }
  
  argz = pop_argz();
  if (!str2u16(argz, &alpha)) {
    printf("invalid vegas alpha\n");
    return;
  }
  uint32_t id;
  argz = pop_argz();
  if (!str2u32(argz, &id)) {
    printf("invalid id\n");
    return;
  }
  struct nn_params *params = get_nn_params(id);
  if (params == NULL) {
    printf ("netnode not use\n");
    return;
  } 
  params->vegas_alpha = (int)alpha;
  params->vegas_beta = (int)beta;
  params->vegas_gamma = (int)gamma;
  params->vegas_ss = (int)ss;
}

BOLT(nn_params_show, "netnode <id> show")
{
  uint32_t id;
  const char *argz = pop_argz();
  if (!str2u32(argz, &id)) {
    printf("invalid id\n");
    return;
  }
  struct nn_params *params = get_nn_params(id);
  if (params)
    nn_params_show(params);
  else
    printf ("failure\n");
}




